package com.wsx.java.boddy.agent;

import net.bytebuddy.implementation.bind.annotation.Origin;
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.SuperCall;

import java.lang.reflect.Method;
import java.util.concurrent.Callable;

/**
 * @author wangshuaixin
 * @Title: com.wsx.java.boddy.agent.LoggerInteceptor
 * @Description: TODO
 * @date 2019/01/23
 */
public class LoggerInteceptor {

    @RuntimeType
    public static Object intercept(@Origin Method method, @SuperCall Callable<?> callable) throws Exception {
        long start = System.currentTimeMillis();
        try {
            return callable.call();
        } finally {
            System.out.println(method +" took times is " + (System.currentTimeMillis() - start));
        }
    }
}
